import { useRef } from "react";

function useIdlePlugin(fetchInstance, fetchOptions) {
  const startTime = useRef(0);
  const optName = fetchOptions.optName;
  return {
    onBefore() {
      startTime.current = performance.now();
    },
    onFinally(params, res, error) {
      console.log(`
        上报操作数据
        操作名称: ${optName}
        操作时长: ${performance.now() - startTime.current}
      `);
    },
  };
}

export default useIdlePlugin;
